package com.efast.cafe.portal.controller.api;

import javax.servlet.http.HttpServletRequest;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.bean.api.PortalApiExtfieldBean;
import com.efast.cafe.portal.service.api.IPortalApiExtfieldService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * <p>Controller</p>
 * <p>Table: portal_api_extfield - </p>
 *
 * @since 2017-09-12 03:54:20
 */
@Controller
@RequestMapping("/frame_center/api")
public class PortalApiExtfieldController extends AbstractController{

	@Autowired
	private IPortalApiExtfieldService portalApiExtfieldService;
	
	
	

	/**
	 * 新增扩展字段
	 * @Date        :      2017年9月13日
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/addApiExtfield")
	public @ResponseBody ResultBean insertApiExtfield(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			portalApiExtfieldService.insertPortalApiExtfield(apiExtfieldBean);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
	
	/**
	 * 删除字段
	 * @Date        :      2017年9月14日
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/delApiExtfield")
	public @ResponseBody ResultBean delApiExtfield(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			portalApiExtfieldService.delPortalApiExtfield(apiExtfieldBean.getId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
	
	/**
	 * 删除字段
	 * @Date        :      2017年9月14日
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/updateApiExtfield")
	public @ResponseBody ResultBean updateApiExtfield(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			portalApiExtfieldService.updateApiExtfield(apiExtfieldBean);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
	
	
	/**
	 * 查询扩展字段详情  只能看自己企业的
	 * @Date        :      2017年9月14日
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/queryExtfieldByObjId")
	public @ResponseBody ResultBean queryExtfieldByObjId(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			result.setObject(portalApiExtfieldService.queryExtfieldByObjId(apiExtfieldBean.getId()));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
	
	/**
	 * 新增扩展字段  ----- 平台级别
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/addApiExtfield_portal")
	public @ResponseBody ResultBean insertApiExtfield_Portal(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			portalApiExtfieldService.insertPortalApiExtfield_portal(apiExtfieldBean);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
	
	/**
	 * 查询扩展字段详情   ----- 平台级别
	 * @param apiExtfieldBean
	 * @param request
	 * @return
	 */
	@RequestMapping("/object/queryExtfieldByObjId_portal")
	public @ResponseBody ResultBean queryExtfieldByObjId_portal(@RequestBody  PortalApiExtfieldBean apiExtfieldBean,HttpServletRequest request){
		ResultBean result = new ResultBean();
		result.setSuccess(true);
		try {
			result.setObject(portalApiExtfieldService.queryExtfieldByObjId_portal(apiExtfieldBean.getId()));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setSuccess(false);
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}else{
				result.setMessage(FAILURE);
			}
		}
		return result;
	}
}